﻿using blackhouse.Translator.Business.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace blackhouse.Translator.Business {
    public class TranslatorLanguagesManager {

        #region Fields

        private CultureInfo[] languages;
        private CultureInfo defaultLanguage;

        #endregion

        #region Constructors

        public TranslatorLanguagesManager() {
            TranslatorConfigurationLanguageCollection languagesConfigCollection = TranslatorConfigurationSection.Get().Languages;
            List<CultureInfo> languagesColl = new List<CultureInfo>();
            foreach (TranslatorConfigurationLanguageElement languageElement in languagesConfigCollection) {
                CultureInfo culture = new CultureInfo(languageElement.Culture);
                if (this.defaultLanguage == null)
                    this.defaultLanguage = culture;
                languagesColl.Add(culture);
                if (languageElement.IsDefault)
                    this.defaultLanguage = culture;
            }
            this.languages = languagesColl.ToArray();
        }

        #endregion

        #region Methods

        public CultureInfo[] GetSupportedLanguages() {
            return this.languages;
        }

        public CultureInfo GetDefaultLanguage() {
            return this.defaultLanguage;
        }

        #endregion

    }
}
